import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    gLoading: false, //是否全局loading
    userInfo:{},  //用户信息
    // 用户具有的角色权限
    roles:[],
    // 用户具有的菜单权限
    permissions:[],
    // 用户菜单列表
    userNavList:[],
  },
  mutations: {
    showGLoading(state) {
      state.gLoading = true
    },
    hideGLoading(state) {
      state.gLoading = false
    },
    savePermissions(state, permissionList) {
      sessionStorage.setItem("permissions", JSON.stringify(permissionList))
      state.permissions = permissionList;
    },
    saveRoles(state, roleList) {
      sessionStorage.setItem("roles", JSON.stringify(roleList))
      state.roles = roleList;
    },
    saveUserInfo(state, userInfo) {
      sessionStorage.setItem("userInfo", JSON.stringify(userInfo))
      state.userinfo = userInfo;
    },
    saveUserNavList(state, userNavList) {
      sessionStorage.setItem("userNavList", JSON.stringify(userNavList))
      state.userNavList = userNavList;
    }
  },
  actions: {
    showGLoading(ctx) {
      ctx.commit('showGLoading');
    },
    hideGLoading(ctx) {
      ctx.commit('hideGLoading');
    },
    savePermissions(ctx, permissionList) {
      ctx.commit('savePermissions', permissionList);
    },
    saveRoles(ctx, roleList) {
      ctx.commit('saveRoles', roleList);
    },
    saveUserInfo(ctx, userInfo) {
      ctx.commit('saveUserInfo', userInfo);
    },
    saveUserNav(ctx, navList) {
      ctx.commit('saveUserNavList', navList);
    }
  },
  modules: {
  }
})
